package cn.net.vote.data.async;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import cn.net.vote.data.domain.PageData;

@Service
public class AsyncQueryData {
	protected Logger logger = LoggerFactory.getLogger(this.getClass());


	
	/** 
	* @param pd
	* @param param
	* @return 
	 * @throws ExecutionException 
	 * @throws InterruptedException 
	*/
	@Async
	public CompletableFuture<PageData> getCaleCheckPointStatistics(PageData pd, PageData param) throws Exception {
		long begin = System.currentTimeMillis();
		logger.info("begin:"+begin);
		CompletableFuture<List<PageData>> innerPdList = null;
		CompletableFuture<List<PageData>> outerPdList = null;
		List<PageData> personTotalList = null;
		List<PageData> carTotalList = null;
		   CompletableFuture.allOf(innerPdList,outerPdList).join();
		personTotalList = new ArrayList<PageData>();
		
		carTotalList = new ArrayList<PageData>();
		
		pd.put("personTotal", personTotalList);
		pd.put("carTotal", carTotalList);
		
		logger.info("end,cost:"+(System.currentTimeMillis()-begin));
		
		
		return  CompletableFuture.completedFuture(pd);
	}

	
	/** 
	* @param pd
	* @param param
	* @return 
	*/
	@Async
	public CompletableFuture<PageData> exportCaleCheckPointStatistics(PageData pd, PageData param)  throws Exception {
		long begin = System.currentTimeMillis();
		logger.info("begin:"+begin);
		CompletableFuture<List<PageData>> innerPdList = null;
		CompletableFuture<List<PageData>> outerPdList = null;
		   CompletableFuture.allOf(innerPdList,outerPdList).join();
		//logger.info("outerPdList"+JSON.toJSONString(outerPdList));
		logger.info("end,cost:"+(System.currentTimeMillis()-begin));
		return CompletableFuture.completedFuture(pd);
	}
	
}
